package com.example.demo.chain.impl;

/**
 * Copyright (c) 2018-2022 ThunderSoft
 * All Rights Reserved by Thunder Software Technology Co., Ltd and its affiliates.
 * You may not use, copy, distribute, modify, transmit in any form this file
 * except in compliance with ThunderSoft in writing by applicable law.
 */

import com.example.demo.chain.filter.AbstractFilter;
import com.example.demo.chain.model.People;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * @author liyuncong
 * @version 1.0
 * @file AFilter
 * @brief AFilter
 * @details AFilter
 * @date 2022-11-02
 *
 * Edit History
 * ----------------------------------------------------------------------------
 * DATE                        NAME               DESCRIPTION
 * 2022-11-02                      liyuncong          Created
 */
@Service
public class AFilter extends AbstractFilter<People> {


    @Override
    public void doFilter(List<People> people) {
        if (CollectionUtils.isEmpty(this.nextDoFilters)) {
            this.nextDoFilters = new ArrayList<>();
            this.nextDoFilters.addAll(people);
        }
        people.forEach(p -> {
            if (p.getStatus() == 1) {
                if (CollectionUtils.isEmpty(this.match)) {
                    this.match = new ArrayList<>();
                }
                this.match.add(p);
                this.nextDoFilters.remove(p);
            }
        });
    }
}
